package com.happy.controller;

import com.happy.pojo.RequestMessage;
import com.happy.service.ModuleService;
import com.happy.service.RequestMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Author: happy
 * @Date: 2021/9/12 19:02
 * @Version: 1.0
 */
@Controller
@RequestMapping
public class JumpController extends BaseController {
    @Autowired
    private RequestMessageService requestMessageService;
    @Autowired
    private ModuleService moduleService;

    @RequestMapping("/home")
    public String gotoHome() {
        return "pages/home/home";
    }


    @RequestMapping(value = "/main", name = "不必登录也可使用该项目的部分功能(例如测试功能)")
    public String gotoMain() {
        List<RequestMessage> modules = moduleService.findModelsByUser(user);
        session.setAttribute("modules", modules);
        return "pages/home/main";
    }

    @RequestMapping("/httpClient")
    public String gotoHttpClient() {
        return "pages/client/HttpClient";
    }


    @RequestMapping("/gotoTry")
    public String gotoTry(@RequestParam Integer id) {
        RequestMessage requestMessage = requestMessageService.findById(id);
        //将查到的案例信息存放到Request域中
        requestMessage.setRequestHeader(requestMessage.getRequestHeader().replaceAll("\r|\n", ""));
        requestMessage.setRequestBody(requestMessage.getRequestBody().replaceAll("\r|\n", ""));
        request.setAttribute("requestMessage", requestMessage);
        return "pages/client/HttpClient";
    }


    @RequestMapping("/gotoTest")
    public String gotoTest(@RequestParam Integer id) {
        RequestMessage requestMessage = requestMessageService.findById(id);
        //将查到的案例信息存放到Request域中
        requestMessage.setRequestHeader(requestMessage.getRequestHeader().replaceAll("\r|\n", ""));
        requestMessage.setRequestBody(requestMessage.getRequestBody().replaceAll("\r|\n", ""));
        request.setAttribute("requestMessage", requestMessage);
        return "pages/client/HttpTestClient";
    }

}
